package com.tanglon.controller;

import com.tanglon.domain.ResponseResult;
import com.tanglon.domain.dto.AddArticleDTO;
import com.tanglon.domain.dto.UpdateArticleDetailDTO;
import com.tanglon.domain.vo.PageVo;
import com.tanglon.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDTO articleDTO){
        return articleService.add(articleDTO);
    }

    /**
     * 获取文章列表
     * @param pageNum
     * @param pageSize
     * @param title 标题
     * @param summary 摘要
     * @return
     */
    @GetMapping("/list")
    public ResponseResult<PageVo> list(Integer pageNum, Integer pageSize, String title, String summary){
        return articleService.getlist(pageNum,pageSize,title,summary);
    }

    @GetMapping("/{id}")
    public ResponseResult getDetail(@PathVariable Long id){
        return articleService.getDetail(id);
    }

    @PutMapping
    public ResponseResult update(@RequestBody UpdateArticleDetailDTO updateArticleDetailDTO){
        return articleService.updateDetail(updateArticleDetailDTO);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id){
        return articleService.deleleArticle(id);
    }

}